// 用户模块
import { getById } from '@/api/user'

export default {
  namespaced: true,
  state() {
    return {
      profile: {
        userId: '',
        schoolId: '',
        userType: '',
        username: '',
        gender: '',
        email: '',
        phone: '',
        nickname: '',
        avatar: '',
        token: ''
      },
      roles: []
    }
  },
  mutations: {
    setUser(state, payload) {
      state.profile = payload
    },
    setRoles(state, payload) {
      state.roles = payload
    },
  },
  actions: {
    getUser({ state, commit }) {
      getById(state.profile.userId).then(res => {
        const data = { ...res.data, token: state.profile.token }
        commit("setUser", data)
      })
    }
  }
}
